package 力扣刷题.探索初级算法.数组.从排序数组中删除重复项;

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {

        Scanner s=new Scanner(System.in);
        int len=s.nextInt();
        int[] nums=new int[len];
        for (int i = 0; i < len; i++) {
            nums[i]=s.nextInt();
        }
        int lenAfterDuplicatesWereDeleted=removeDuplicates(nums);
        for (int i = 0; i < lenAfterDuplicatesWereDeleted; i++) {
            System.out.print(nums[i]);
        }
        System.out.println();
        System.out.println(lenAfterDuplicatesWereDeleted);
    }
    public static int removeDuplicates(int[] nums) {
        int prevPointer=0,laterPointer=0;
        if (nums.length==0)
            return 0;
        else if(nums.length==1)
            return 1;
        else {
            laterPointer++;
            while(laterPointer!=nums.length) {
                if(nums[laterPointer]!=nums[prevPointer]) {
                    prevPointer=prevPointer+1;
                    nums[prevPointer]=nums[laterPointer];
                }
                laterPointer=laterPointer+1;
            }
        }
        return prevPointer+1;
    }
}
